<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="minimum-scale=1.0, initial-scale=1.0, width=device-width"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
    <style type="text/css">
        .header {
            padding: 2.5rem 0.5rem 2rem 0.5rem;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="padding-top:25px;">
        <a class="aui-pull-left aui-btn" onclick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">E文通</div>
        <a class="aui-pull-right aui-btn nav-btn" id="headList">
            <span class="aui-iconfont aui-icon-more"></span>
        </a>
    </header>
<div class="head-d"></div>
    <!-- <div class="content-t" id="conHead">
        <p2 id="title"></p2>
        <p id="create_time"></p>
    </div> -->

    <div class="content-t" id="conHead">
        <p2 id="title"></p2>
        <p>
            <span>作者：<span2 id="conAuth">可大金服</span2></span>
            <span id="create_time">2018-11-20</span>
            <span>编号：<span2 id="conNum">JKD156846816516546</span2></span>
        </p>
    </div>

    <div class="content" id="content">
    </div>

    <div class="content-d" style="display: none" id="down">
        附件：
        <span onclick="download_file();">下载</span>
    </div>

    <div class="content-jg" id="applyBtn" style="display: none">
        <span class="aui-iconfont aui-icon-date"></span>
        <p>该文档已过查看期，如需查看请点击申请</p>
        <div class="aui-btn aui-btn-success aui-btn-sm" onclick="shenqing();">申请</div>
    </div>

    <div class="content-jg" id="applying" style="display: none">
        <span class="aui-iconfont aui-icon-date"></span>
        <p>该文档正在申请中，请耐心等待</p>
        <div class="aui-btn aui-btn-success aui-btn-sm" onclick="closeWin();">返回</div>
    </div>

    <div class="content-jg" id="bohui" style="display: none">
        <span class="aui-iconfont aui-icon-date"></span>
        <p>该文档申请已被驳回</p>
        <div class="aui-btn aui-btn-success aui-btn-sm" onclick="closeWin();">返回</div>
    </div>

    <!-- 顶部弹出菜单 -->
    <div class="nav aui-popup-top-right">
        <div class="aui-popup-arrow"></div>
        <div class="aui-popup-content">
            <ul class="aui-list aui-list-noborder">
                <!-- <li class="aui-list-item">
                    <div class="aui-list-item-label-icon">
                        <i class="aui-iconfont aui-icon-forward aui-text-success"></i>
                    </div>
                    <div class="aui-list-item-inner aui-list-item-middle">

                        <div class="aui-list-item-inner aui-list-item-middle" onclick="download_word();">
                            导出
                        </div>
                    </div>
                </li> -->
                <li class="aui-list-item" id = "browse" style="display: none">
                    <div class="aui-list-item-label-icon">
                        <i class="aui-iconfont aui-icon-menu aui-text-success"></i>
                    </div>
                    <div class="aui-list-item-inner aui-list-item-middle" onclick="readPeople();">
                        浏览记录
                    </div>
                </li>
            </ul>
        </div>
    </div>

    <!-- <div class="foot-t"></div>
<ul class="foot">
  <li>
    <i class="aui-iconfont aui-icon-home"></i>
    <p>首页</p>
  </li>
  <li>
    <i class="aui-iconfont aui-icon-my"></i>
    <p>我的</p>
  </li>
</ul>
</body> -->

    <script type="text/javascript" src="./script/api.js"></script>
    <script type="text/javascript">
        function openClub() {
            var delay = 0;
            if (api.systemType != 'ios') {
                delay = 300;
            }
            api.openWin({
                name: 'club_win',
                url: './html/club_win.html',
                bounces: false,
                delay: delay,
                slidBackEnabled: true,
                vScrollBarEnabled: false,
                progress: {
                    type: "page"
                }
            });
        }
        $(".nav-btn").on("click", function() {
            $(".nav").slideToggle(100);
        })
        $(".nav .aui-list-item").on("click", function() {
            $(".nav").hide();
        })

        function closeWin() {
            api.closeWin({});
        }

        function readPeople() {
            api.openWin({
                name: 'list',
                url: './list.html',
                pageParam: {
                    id: id,
                }
            });

        }

        function shenqing() {
            api.openWin({
                name: 'form',
                url: './form.html',
                pageParam: {
                    sender_id: sender_id,
                    con_id: id
                }
            });

        }

        var id = '';
        var sender_id = "";
        var file_id = '';
        apiready = function() {

            id = api.pageParam.id; // 内容id
            var userid = $api.getStorage('id');
            updateData(id);
        }

        function updateData(id) {

            api.showProgress({
                style: 'default',
                animationType: 'fade',
                title: '努力加载中...',
                text: '先喝杯茶...',
                modal: false
            });

            var userid = $api.getStorage('id');
            // alert('');
            var url = 'http://oa.big-wealth.com/index.php?m=&c=info&a=read_api&api_auth_id=' + userid + '&id=' + id;

            // console.log(url);
            api.ajax({
                url: url,
                method: 'get',

            }, function(ret, err) {
                if (ret) {
                  // [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
                    // alert(JSON.stringify(ret.date));
                    $('#conNum').text(ret.date.number);
                    $('#create_time').text(ret.date.create_time);
                    api.hideProgress();

                    var end_time = api.pageParam.end_time;
                    sender_id = api.pageParam.sender_id;
                    var name = api.pageParam.name;
                    var num = api.pageParam.num;
                    var browse = ret.auth.admin;
                    if (browse) {
                       $("#browse").show();
                    }
                    //  console.log(JSON.stringify(ret));

                    if (end_time == 0) {

                        updateCon(ret.date);
                    } else {

                        // 是否为空  如果 为空 说明没有申请  就直接到申请页   如果不为空   0：未审核 1：审核通过 2：驳回
                        console.log(JSON.stringify(ret.apply));

                        if (ret.apply == null || ret.apply == "") {

                            var timestamp = parseInt(Date.parse(new Date())) / 1000;

                            if (timestamp >= end_time) {
                                $("#applyBtn").show();
                                $("#content").hide();
                                $("#conHead").hide();
                                $("#headList").hide();

                            } else {

                                updateCon(ret.date);
                            }

                        } else {
                            if (ret.apply.status == 0) {
                                $("#applying").show();
                                $("#content").hide();
                                $("#conHead").hide();
                                $("#headList").hide();
                            }
                            if (ret.apply.status == 1) {
                                updateCon(ret.date);
                            }
                            if (ret.apply.status == 2) {
                                $("#bohui").show();
                                $("#content").hide();
                                $("#conHead").hide();
                                $("#headList").hide();
                            }

                        }
                    }

                } else {
                    alert(JSON.stringify(err));
                }
            });

        }

        function updateCon(data) {

            var index = getDate(data.create_time).search(' ')
            // var create_time = getDate(data.create_time).substr(0, index);

            data.content = data.content.replace(/Uploads\//g, 'http://oa.big-wealth.com/Uploads/');
            data.content = data.content.replace(/m\/\//g, '/');
            data.content = data.content.replace(/\/http:/g, 'http:');

            if (data.add_file != '') {
                file_id = data.add_file;
                $("#down").show();
            }

            $("#title").text(data.name);
            $("#create_time").text(data.create_time);
            $("#content").html(data.content);

        }

        function download_word() {
            var userid = $api.getStorage('id');
            var url = 'http://oa.big-wealth.com/index.php?m=&c=info&a=info_down&api_auth_id=' + userid + '&id=' + id;

            if (api.systemType == 'ios') {
                // delay = 300;
                api.openApp({
                    iosUrl: url, //打开微信的，其中weixin为微信的URL Scheme

                });

            } else {
                api.openApp({
                    androidPkg: 'android.intent.action.VIEW',
                    mimeType: 'text/html',
                    uri: url,
                }, function(ret, err) {
                    if (ret) {
                        // alert(JSON.stringify(ret));
                    } else {
                        // alert(JSON.stringify(err));
                    }
                });
            }

        }

        function download_file() {
            var id = $api.getStorage('id');
            var url = 'http://oa.big-wealth.com/index.php?m=&c=Info&a=downApi&attach_id=' + file_id + '&api_auth_id=' + id;
            var path = '';
            api.ajax({
                url: url,
                method: 'post',
                data: {
                    values: {},
                }
            }, function(ret, err) {
                if (ret) {
                    // alert(JSON.stringify(ret));
                    path = 'http://oa.big-wealth.com/' + ret.download;
                    api.download({
                        url: path,
                        // savePath : 'fs://test.png',
                        report: true,
                        cache: true,
                        allowResume: true
                    }, function(ret, err) {
                        if (ret.state == 1) {
                            // alert(JSON.stringify(ret));
                            // 本地路径
                            local_path = ret.savePath;
                            // alert(local_path);
                            // 下载成功 预览
                            var docInteraction = api.require('docInteraction');
                            docInteraction.open({
                                path: local_path,
                            }, function(ret, err) {
                                if (err) {
                                    alert(JSON.stringify(err));
                                } else {
                                    alert(JSON.stringify(ret));
                                }
                            });
                        } else {

                        }
                    });

                } else {
                    alert(JSON.stringify(err));
                }
            });
        }
    </script>

</html>
